package com.tc.minio;/*
 * MinIO Java SDK for Amazon S3 Compatible Cloud Storage, (C) 2015 MinIO, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//140.82.112.4
//199.232.69.194
import io.minio.BucketExistsArgs;
import io.minio.MinioClient;
import io.minio.ObjectWriteResponse;
import io.minio.UploadObjectArgs;
import io.minio.errors.MinioException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class BucketExists {
  /** MinioClient.bucketExists() example. */
  public static void main(String[] args)
      throws IOException, NoSuchAlgorithmException, InvalidKeyException {
    try {
      /* play.min.io for test and development. */
      final MinioClient minioClient = MinioFactory.getMinioClient();

      /* Amazon S3: */
      // MinioClient minioClient =
      //     MinioClient.builder()
      //         .endpoint("https://s3.amazonaws.com")
      //         .credentials("YOUR-ACCESSKEY", "YOUR-SECRETACCESSKEY")
      //         .build();

      // Check whether 'my-bucketname' exist or not.
      boolean found =
          minioClient.bucketExists(BucketExistsArgs.builder().bucket("dockerminio").build());
      if (found) {
        System.out.println("dockerminio exists");
      } else {
        System.out.println("dockerminio does not exist");
      }
      UploadObjectArgs uploadObjectArgs = UploadObjectArgs.builder().bucket("dockerminio")
              .object("/a/b/test111.png")
              .filename("I:\\contain-home\\minio-project\\java-project\\src\\main\\resources\\userface1.jpg")
              .build();
      ObjectWriteResponse objectWriteResponse = minioClient.uploadObject(uploadObjectArgs);
      String etag = objectWriteResponse.etag();
      System.out.println("etag:  "+etag);
      //ETag:   "cda24afc5d5be54466ca06b16a846a85"
      System.out.println("versionId:  "+objectWriteResponse.versionId());
      System.out.println("headers:  "+objectWriteResponse.headers());
      System.out.println("bucket:  "+objectWriteResponse.bucket());
      //bucket:  dockerminio
      System.out.println("object:  "+objectWriteResponse.object());
      //object:   /a/b/test111.png
      System.out.println("region:  "+objectWriteResponse.region());
    } catch (MinioException e) {
      System.out.println("Error occurred: " + e);
    }
  }
}
